package com.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.service.RoleService;
import com.util.LayuiTable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@Transactional
@RequestMapping("/role")
public class RoleController {
    @Autowired
    public RoleService roleService;

    //allemp页面职位下拉查询
    @RequestMapping("/list")
    @ResponseBody
    public String rolelist(){
        return JSON.toJSONString(roleService.findByState());
    }

    //allrole页面列表
    @RequestMapping("/rlist")
    @ResponseBody
    public String rolerlist(){
        return JSON.toJSONString(LayuiTable.tableData(roleService.findAllRole().size(),roleService.findAllRole()), SerializerFeature.DisableCircularReferenceDetect);
    }

    //    通过职位id修改职位表状态
    @RequestMapping("/updstate")
    @ResponseBody
    public String roleUpdstate(@RequestParam Integer state,@RequestParam Integer rid){
        if (roleService.updateC_roleByroleid(state, rid)==0){
            return "false";
        }else {
            return "true";
        }
    }

    //通过eid查询职位
    @RequestMapping("/findRoleid")
    @ResponseBody
    public Integer findRoleid(HttpSession session){
        Integer empid= (Integer) session.getAttribute("loginEmpno");
        Integer roleid=roleService.CERselectEmpid(empid).get(0).getRoleid();
        return roleid;
    }
}
